package com.example.administrator.x3picturetransliteration.Home.Adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.x3picturetransliteration.Base.BaseListViewAdapter;
import com.example.administrator.x3picturetransliteration.Bean.OrderListBean;
import com.example.administrator.x3picturetransliteration.R;

import java.math.BigDecimal;
import java.util.List;

/**
 * 消费记录
 * Created by Administrator on 2019/8/26.
 */

public class ConsumptionAdapter extends BaseListViewAdapter{

    private List<OrderListBean> mData;

    public ConsumptionAdapter(Context context,List<OrderListBean> mData) {
        super(context);

        this.mData = mData;
    }

    @Override
    public int getLayoutView() {
        return R.layout.home_item_consumption;
    }

    @Override
    public int mCount() {
        return mData.size();
    }

    @Override
    public void logic(ViewHolder mViewHolder, View view, int position) {

        IViewHolder mIViewHolder = (IViewHolder)mViewHolder;

        mIViewHolder.OrderNumberText.setText(mData.get(position).getOrderNo());
        mIViewHolder.NameText.setText(mData.get(position).getItemName());

        if (mData.get(position).getType()==0){

            mIViewHolder.DurationText.setText("单次");

        }else if (mData.get(position).getType()==24){

            mIViewHolder.DurationText.setText("两年");

        }else if (mData.get(position).getType()==6){

            mIViewHolder.DurationText.setText("半年");

        }else if (mData.get(position).getType()==12){

            mIViewHolder.DurationText.setText("一年");

        }else if (mData.get(position).getType()==9999){

            mIViewHolder.DurationText.setText("永久");

        }else{

            mIViewHolder.DurationText.setText(mData.get(position).getType() + "月");
        }

        mIViewHolder.PaymentMethodText.setText(mData.get(position).getPayType()==1?"微信":"支付宝");

        mIViewHolder.PaymentTimeText.setText(mData.get(position).getPayTime());

        mIViewHolder.moneyText.setText("￥" + (mData.get(position).getPayPrice().divide(new BigDecimal("100"))).toString());

    }

    @Override
    public ViewHolder InstantiationView(View mview) {

        IViewHolder mIViewHolder = new IViewHolder();

        mIViewHolder.OrderNumberText = mview.findViewById(R.id.OrderNumberText);
        mIViewHolder.NameText = mview.findViewById(R.id.NameText);
        mIViewHolder.DurationText = mview.findViewById(R.id.DurationText);
        mIViewHolder.PaymentMethodText = mview.findViewById(R.id.PaymentMethodText);
        mIViewHolder.moneyText = mview.findViewById(R.id.moneyText);
        mIViewHolder.PaymentTimeText = mview.findViewById(R.id.PaymentTimeText);

        return mIViewHolder;
    }

    private class IViewHolder extends ViewHolder{

        TextView OrderNumberText; //订单编号
        TextView NameText; //商品名称
        TextView DurationText; //会员时长
        TextView PaymentMethodText; //支付方式
        TextView moneyText; //支付金额
        TextView PaymentTimeText; //支付时间

    }
}
